package online.shenjian.hadoop.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author shenjian
 * @since 2023/2/6
 */
public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    private FlowBean keyOut = new FlowBean();
    private Text valueOut = new Text();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, FlowBean, Text>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split(" ");
        String phone = split[1];
        String up = split[3];
        String down = split[4];

        keyOut.setUpFlow(Long.parseLong(up));
        keyOut.setDownFlow(Long.parseLong(down));
        keyOut.setTotalFlow();
        valueOut.set(phone);

        context.write(keyOut, valueOut);
    }
}
